package smedi.ismedi.web.bff.controller.constructionproject;

import com.smedi.ismedi.constructionproject.api.dto.request.BidSectionRequest;
import com.smedi.ismedi.constructionproject.api.dto.response.BidSectionResponse;
import com.smedi.ismedi.constructionproject.api.dto.response.BidSectionViewResponse;
import com.smedi.ismedi.constructionproject.api.feign.RemoteBidSectionFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import smedi.ismedi.web.bff.controller.BaseController;

/**
 * 项目标段接口
 *
 * @author xulinjun
 */
@Slf4j
@RestController
@Api(tags = {"项目标段接口"})
@RequestMapping("/webbff/v1/bidSection")
@AllArgsConstructor
public class BidSectionController extends BaseController {
    private final RemoteBidSectionFeignApi remoteBidSectionFeignApi;

    /**
     * 保存标段信息
     *
     * @param bidSectionRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "保存标段信息")
    @PostMapping(value = "/saveBidSection")
    public ResponseData<BidSectionResponse> postSaveBidSection(@Validated @RequestBody BidSectionRequest bidSectionRequest) {
        return remoteBidSectionFeignApi.postSaveBidSection(bidSectionRequest);
    }

    /**
     * 查询标段信息分页
     *
     * @param offset
     * @param pageSize
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "查询标段信息分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "offset", value = "页码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/queryBidSectionPagination")
    public ResponseData<PaginationData> getQueryBidSectionPagination(@RequestParam("offset") Long offset,
                                                                     @RequestParam("pageSize") Long pageSize,
                                                                     @RequestParam("projectId") Long projectId) {
        return remoteBidSectionFeignApi.getQueryBidSectionPagination(offset, pageSize, projectId);
    }

    /**
     * 查询标段信息
     *
     * @param bidSectionId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "查询标段信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "bidSectionId", value = "标段id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/queryBidSectionView")
    public ResponseData<BidSectionViewResponse> getQueryBidSectionView(@RequestParam("bidSectionId") Long bidSectionId) {
        return remoteBidSectionFeignApi.getQueryBidSectionView(bidSectionId);
    }

    /**
     * 删除标段信息
     *
     * @param bidSectionId
     * @return
     */
    @ApiOperation(httpMethod = "DELETE", value = "删除标段信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "bidSectionId", value = "标段id", dataType = "Long", dataTypeClass = Long.class),
    })
    @DeleteMapping(value = "/deleteBidSection")
    public ResponseData<Boolean> deleteBidSection(@RequestParam("bidSectionId") Long bidSectionId) {
        return remoteBidSectionFeignApi.deleteBidSection(bidSectionId);
    }

    /**
     * 判断项目组织是否被用于标段
     *
     * @param projectOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "判断项目组织是否被用于标段")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectOrganizationId", value = "项目组织id", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping(value = "/checkProjectOrganizationBeUsedInBidSection")
    public ResponseData<Boolean> getCheckProjectOrganizationBeUsedInBidSection(@RequestParam("projectOrganizationId") Long projectOrganizationId) {
        return remoteBidSectionFeignApi.getCheckProjectOrganizationBeUsedInBidSection(projectOrganizationId);
    }
}
